<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增问题')"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-question-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">问题内容：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" name="questuionContent">
                <div class="summernote" id="questuionContent"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">知识点类型：</label>
            <div class="col-sm-9">
                <select class="form-control" name="questionTypeId">
                    <option th:value="0">请选择</option>
                    <option th:each="type : ${wbQuestionTypeList}" th:value="${type.typeId}" th:text="${type.typeName}">
                        JavaEE
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">题型：</label>
            <div class="col-sm-9">
                <select class="form-control" name="itemTypeId">
                    <option th:value="0">请选择</option>
                    <option th:each="item : ${wbItemTypeList}" th:value="${item.itemTypeId}" th:text="${item.itemTypeName}">
                        单选题
                    </option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">选项内容：</label>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">A：</label>
            <div class="col-sm-9">
                <input type="text" name="options[0].optionContent" class="form-control" placeholder="请输入选项内容">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">B：</label>
            <div class="col-sm-9">
                <input type="text" name="options[1].optionContent" class="form-control" placeholder="请输入选项内容">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">C：</label>
            <div class="col-sm-9">
                <input type="text" name="options[2].optionContent" class="form-control" placeholder="请输入选项内容">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">D：</label>
            <div class="col-sm-9">
                <input type="text" name="options[3].optionContent" class="form-control" placeholder="请输入选项内容">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">答案选项：</label>
            <div class="col-sm-9">
                <label class="check-box">
                    <input type="checkbox" value="true" name="optionRW[0]" >A</label>
                <label class="check-box">
                    <input type="checkbox" value="true" name="optionRW[1]" >B</label>
                <label class="check-box">
                    <input type="checkbox" value="true" name="optionRW[2]">C</label>
                <label class="check-box">
                    <input type="checkbox" value="true" name="optionRW[3]">D</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">最高分：</label>
            <div class="col-sm-8">
                <input name="topScore" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">最低分：</label>
            <div class="col-sm-8">
                <input name="lowestMark" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    var prefix = ctx + "wbgame/question"
    $("#form-question-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-question-add').serialize());
        }
    }

    $(function () {
        $('.summernote').summernote({
            lang: 'zh-CN',
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });
</script>
</body>
</html>